﻿/*-----------------------------------------------
// File: LoaderBase.cs 
// Description: Loader加载资源基类 
// Author: Shaobing	492057342@qq.com
-----------------------------------------------*/
using UnityEngine;
using System.Collections;
using AssetLoad;

namespace AssetLoad
{
    public class LoaderBase
    {
        public virtual string GetPrefix() { return ""; }
        protected virtual UnityEngine.Object Load(string resourceName)
        {
            var obj = ResourceManager.Instance.LoadResource(GetPrefix() + resourceName);
            if (obj != null)
                return GameObject.Instantiate(obj);
            return null;
        }
        protected virtual void Unload(UnityEngine.Object obj, string resourceName)
        {
            if (obj != null)
            {
                GameObject.Destroy(obj);
            }
            obj = null;
            ResourceManager.Instance.UnloadResource(GetPrefix() + resourceName);
        }
        public virtual bool IsLoadComplete(string resourceName)
        {
            if (ResourceManager.Instance.GetResource(GetPrefix() + resourceName))
                return true;
            return false;
        }
        protected virtual void LoadAsync(string resourceName)
        {
            AssetBundleManager.Instance.LoadAssetBundle(GetPrefix() + resourceName);
            //ResourceManager.Instance.LoadResourceAsync(GetPrefix() + resourceName);
        }
        protected virtual UnityEngine.Object Get(string resourceName)
        {
            return ResourceManager.Instance.GetResource(GetPrefix() + resourceName);
        }
    }

}